package com.entrogy.dao;

/**
 * @ClassName KaoqinDao
 * @Description
 * @Author luoxingjiang
 * @Date 2019/7/5 0005 上午 9:18
 * @Version 1.0
 **/

import com.entrogy.bean.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Mapper
public interface KaoqinMapper {




    int getIntersection(@Param(value = "tableName") String tableName, @Param(value = "i") int i, @Param(value = "classId") String classId);

    Integer getLeaveNum(String course_id,int school_code);

    /**
     * 查询班主任所带班级的信息
     * @param uid
     * @param schoolCode
     * @return
     */
    List<ClassEntity> getLeaderClassInfo(@Param(value = "uid") String uid, @Param(value = "schoolCode") Integer schoolCode);

    /**
     * 查询年级组长所带年级的信息
     * @param uid
     * @param schoolCode
     * @return
     */
    List<GradeEntity> getLeaderGradeInfo(@Param(value = "uid") String uid, @Param(value = "schoolCode") Integer schoolCode);

    /**
     * 得到这个年级的所有班级
     * @param gradeId
     * @param schoolCode
     * @return
     */
    ArrayList<ClassEntity> getGradeClassList(@Param(value = "gradeId") String gradeId, @Param(value = "schoolCode") Integer schoolCode);


    /**
     * 返回某班晚上总考勤人数即某班住校人数
     * @param classId
     * @return
     */
    Integer getLiveInSchoolNum(String classId);

    /**
     * 查询当天请假的
     * @param stuId
     * @return
     */
    LeaveRecordEntity getLeaveRecord(int stuId);

    /**
     * 查询通过记录
     * @param tableName
     * @param stuId
     * @return
     */
    PassRecordBean getPassRecord(@Param(value = "tableName") String tableName, @Param(value = "stuId") Integer stuId);

    /**
     * 通过生活老师的uid查询该校宿舍的迟到记录
     * @param tableName
     * @param uid
     * @return
     */
    List<PassRecordBean> listLatePerson(@Param(value = "tableName") String tableName, @Param(value = "uid") Integer uid);

    /**
     * 查询学校的请假记录
     * @param schoolCode
     * @return
     */
    List<LeaveRecordEntity> listLeaveRecords(Integer schoolCode);

    /**
     * 根据班级ID查询出所通行的记录
     * @param classId
     * @return
     */
    @Select("select * from leave_record where pass_times=1 and isauthority=1 and teacher_id=(select id from user where school_code = #{schoolCode}class_id=#{classId} LIMIT 1) ")
    List<LeaveRecordEntity> getLeaveRecordByCId(@Param("classId") String classId,@Param("schoolCode") int schoolCode);

    @Select("select tt.record_id,tt.person_id, tt.person_name, tt.machine_name, tt.record_time, tt.flag, s.course_id from ${tableName} tt,student_information s where tt.person_id=s.student_thdid and s.school_code = #{schoolCode} and s.course_id=#{courseId} and flag in (1, 7)")
    List<PassRecordEntity> getMorningInfoByTea(@Param("tableName") String tableName, @Param("courseId") String courseId, @Param("schoolCode") int schoolCode);

    @Select("select tt.record_id, tt.person_id, tt.person_name, tt.machine_name, tt.record_time,tt.flag, s.course_id from ${tableName} tt,student_information s where tt.person_id=s.student_thdid and s.course_id=#{courseId} and flag in (2, 3, 8)")
    List<PassRecordEntity> getNoonInfoByTea(@Param("tableName") String tableName,@Param("courseId") String courseId,@Param("schoolCode") int schoolCode);

    @Select("select tt.record_id, tt.person_id, tt.person_name, tt.machine_name, tt.record_time, tt.flag, s.course_id from ${tableName} tt,student_information s where tt.person_id=s.student_thdid and course_id=#{courseId} and flag in (4, 9)")
    List<PassRecordEntity> getNightInfoByTea(@Param("tableName") String tableName,@Param("courseId") String courseId, @Param("schoolCode") int schoolCode);

    @Select("select course_id, course_name from course_information where school_code = #{schoolCode} and gride_id like '%#{courseId}%'")
    ArrayList<Object[]>  getGradeInfo(@Param("courseId") String courseId,@Param("schoolCode") int schoolCode);

    /**
     * 获取全学校的班级信息
     * @param schoolCode
     * @return
     */
    @Select("select course_id,course_name from course_information where school_code = #{schoolCode}")
    ArrayList<Object[]> getTotalClassInfo(@Param("schoolCode") int schoolCode);

    @Select("select t.person_name from ${tableName} t,student_information s where t.person_id=s.student_thdid and s.school_code = #{schoolCode} and s.course_id=#{courseId} and t.flag=10")
    List<String> getPassRecordStuName(@Param("tableName") String tableName, @Param("courseId") String course_id,@Param("schoolCode") int schoolCode);

    @Select("select student_name from leave_record,student_information where teacher_id=#{uid} and isauthority=1 and leave_record.student_id=student_information.id and student_information.school_code = #{schoolCode} and start_time <= #{startTime} and end_time >= #{endTime}")
    List<String> getStudentNamesForLeave(@Param("uid") String uid,@Param("startTime") Date startTime, @Param("endTime") Date endTime,@Param("schoolCode") int schoolCode);

    @Select("select student_name from student_information where school_code = #{schoolCode} and course_id=#{courseId} and student_name not in (${name})")
    List<String> getAbnormalByCourseId(@Param("courseId") String course_id, @Param("name") String name,@Param("schoolCode") int schoolCode);
}

